package com.example.agriculturemachine.ui.activity;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.widget.Button;

import androidx.viewpager.widget.ViewPager;

import com.example.agriculturemachine.R;
import com.example.agriculturemachine.base.BaseActivity;
import com.example.agriculturemachine.ui.adapter.IntroductoryAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class IntroductoryActivity extends BaseActivity {

    @BindView(R.id.introductory_viewPager)
    public ViewPager mViewPager;
    private Button mButton;
    private List<View> mViewList;


    @Override
    protected int getLayoutResId() {
        return R.layout.activity_introducttory;
    }

    @Override
    protected void initView() {
        mViewList = new ArrayList<>();
        mViewList.add(getView(R.layout.introductory_1));
        View view = getView(R.layout.introductory_2);

        Button enterLogin = view.findViewById(R.id.enterLogin);




        enterLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(IntroductoryActivity.this,LoginActivity.class));
            }
        });
        //enterLogin.setVisibility(View.INVISIBLE);


        mViewList.add(view);


        IntroductoryAdapter introductoryAdapter = new IntroductoryAdapter(mViewList);
        mViewPager.setAdapter(introductoryAdapter);

        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
               if(position==1){
//                   enterLogin.setVisibility(View.GONE);
//                   Animation animBottomOut = AnimationUtils.loadAnimation(IntroductoryActivity.this,R.anim.button_out);
//animBottomOut.setDuration(240);//动态设置多长时间，xml里面设置了，这里就不要写了
//                   enterLogin.setVisibility(VISIBLE);
//                   enterLogin.startAnimation(animBottomOut);
                   int cx = enterLogin.getWidth() / 2;
                   int cy = enterLogin.getHeight() / 2;
                   float radius=enterLogin.getWidth();
                   Animator anim = ViewAnimationUtils.createCircularReveal(enterLogin, cx, cy, radius, 0);
                   anim.addListener(new AnimatorListenerAdapter() {
                       @Override
                       public void onAnimationEnd(Animator animation) {

                           enterLogin.setVisibility(View.VISIBLE);
                       }
                   });
                   anim.setDuration(2000);
                   anim.start();
               }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    private View getView(int ResId) {
        View view = LayoutInflater.from(this).inflate(ResId, null);

        return view;
    }
}